<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html>
<head>
	{include file='header.tpl' JS=$smarty.const.BAOGG_JS CSS=$smarty.const.BAOGG_CSS}
        <script type="text/javascript"> 
        {literal}
          	Ext.onReady(function(){
          		Ext.get("submit").on("click",function(){
	          		Ext.Ajax.request({
	          		    form: 'form1',
	          		  	success: function(form, action) {		
	          		  		//console.info(action);		
	          		  	  var result=Ext.decode(form.responseText);
	          		  	  if(result.success){
		          		  		 top.top.Ext.example.msg('{/literal}{$LANG.save}{literal}', '{/literal}{$LANG.save_ok}{literal}');
			          		  	 parent.Ext.getCmp("user_group_role_{/literal}{$user_id}{literal}").close();
	          		  	  }else{
		          		  		 Ext.MessageBox.show({
			          		           title: '{/literal}{$LANG.save_fail}{literal}',
			          		           msg: result.msg,
			          		           buttons: Ext.MessageBox.OK,
			          		           icon:  Ext.MessageBox.ERROR
			          		       });
	          		  	  }					   				
	     			    },
	     			   failure: function(form, action) {
	    					switch (action.failureType) {
	    					    case Ext.form.Action.CLIENT_INVALID:
	    						top.Ext.example.msg('{/literal}{$LANG.save_fail}{literal}', "Form fields may not be submitted with invalid values");
	    						break;
	    					    case Ext.form.Action.CONNECT_FAILURE:
	    						top.Ext.example.msg('{/literal}{$LANG.save_fail}{literal}', "Ajax communication failed");
	    						break;
	    					    case Ext.form.Action.SERVER_INVALID:
	    					       top.Ext.example.msg('{/literal}{$LANG.save_fail}{literal}', action.result.msg);
	    					       break;
	    					    default:
	    					      top.Ext.example.msg('{/literal}{$LANG.save_fail}{literal}', action.result.msg);
	    					      break;
	    				       }
	    				   }
	          		});

          		});
          		 
          	});
          	{/literal}
          </script>	
</head>
<body>       
<form method="post" id="form1" name="form1" action="{$form_url}">

	<div id="toolbar">
		<input type="button" id="submit" value="{$LANG.save}" />
	</div>
<hr />
	
	<div id="form">
		<!-- 
		<div>
		<input type="checkbox" name="include_sub_group" id="include_sub_group" /><lable for="include_sub_group">{$LANG.include_sub_group}</lable>
		</div>
		--> 
		<br />
		</div>
		<table class="grid">
			<thead>
				<th><!-- <input type="checkbox" /> --></th>
				
				<th>{$LANG.user_group_id}</th>
				<th>{$LANG.role_id}</th>
				
			</thead>
			<tbody>
			<tr>
				<td><input type="checkbox" name="user_group_id[0]"
				{if isset($user_group_roles.0)}
					checked
				 {/if}
				
				  /></td>
				<td>{$LANG.personal}</td>
				<td>
				{foreach item=role from=$roles}
					{if $role.is_default eq 1}
					
						<input type="checkbox" name="role_id[0][]" value="{$role.role_id}" 
						{if isset($user_group_roles.0[$role.role_id])}
							checked
						 {/if}
						/><lable>{$role.role_name}</lable> &nbsp;
					{/if} 
				{/foreach}
				</td>	
			</tr>
			{foreach name=outer item=user_group from=$user_groups}			
			<tr>
				<td><input type="checkbox" name="user_group_id[{$user_group.user_group_id}]"
				{if isset($user_group_roles[$user_group.user_group_id])}
					checked
				 {/if} /></td>
				<td> {$user_group.user_group_name}</td>
				<td>
				{foreach item=role from=$roles}
					{if  $role.is_default eq 0}
						<input type="checkbox" name="role_id[{$user_group.user_group_id}][]" value="{$role.role_id}" 
							{if isset($user_group_roles[$user_group.user_group_id][$role.role_id])}
							checked
						 {/if}
						/><lable>{$role.role_name}</lable> &nbsp; 
					{/if}
				{/foreach}
				</td>	
			</tr>
			{/foreach}
			</tbody>
		</table>
		<input type="hidden" name="user_id" value="{$user_id}" />

		

</form>
</body>
</html>